
package system.base;

import framework.core.*;
import system.SelectManager;
import system.data.*;

/*
	Author    :Jackey
	CreateTime:2008-02-15 17:17:01
*/
public class UserMenuinfo extends UserMenuinfoBase 
{

//----system generated start----// 	
public UserMenuinfo() 
{
	
}

private static void delete(DBConnection con,String id) throws Exception
{
	Conditions conditions = new Conditions();

	conditions.add(ID,id);
	
	delete(con,TABLE_NAME,conditions);
}
public static UserMenuinfo fetch()
{
	return new UserMenuinfo();
}
public static UserMenuinfo copy(UserMenuinfo srcObj)
{
	UserMenuinfo obj = fetch();
	obj.copyBase(srcObj);
	return obj;
}
public static UserMenuinfo fetch(DBConnection con,String id) throws Exception
{
	Conditions conditions = new Conditions();

	conditions.add(ID,id);
	
	return fetch(con,conditions);
}
public static UserMenuinfo fetch(DBConnection con,Conditions conditions) throws Exception
{
	DBResult result = null;
	try
	{
		result = DBEngine.doSelect(con,"select * from " + TABLE_NAME,conditions);
		java.sql.ResultSet rs = result.getRs();
		UserMenuinfo obj = null;
		if(rs.next())
		{
			obj = fetch(rs);
		}
		return obj;
	}
	finally
	{
		if(result!=null) result.clear() ;
	}
}
public static UserMenuinfo fetch(java.sql.ResultSet rs) throws Exception
{
	UserMenuinfo obj = new UserMenuinfo();
	obj.initObject(rs);
	return obj;
}
protected void getUnique(DBConnection con) throws Exception
{
		setId(DBEngine.getId(con));
}
//----system generated end----//



//----add by Jackey start----//


//----add by Jackey end----//

//----add by Sindy start----//
public static ObjectList fetchbyUserId(String code,DBConnection con) throws Exception {
    
    ObjectList list = ObjectList.getList();
    Conditions conditions = new Conditions();
    
    if (code.equalsIgnoreCase(ConstDefine.T_USER_SUPERADMIN_ID))
    {
        Conditions menucs = new Conditions();
        menucs.add(MenuInfo.PARENT_CODE,Conditions.NOT_EQUAL,MenuInfo.PARENT_CODE_TOP_INT);
        ObjectList menuList = MenuInfo.fetch().search(con, menucs);
        for(int i=0;i<menuList.size();i++)
        {
            MenuInfo mi = (MenuInfo)menuList.get(i);
            UserMenuinfo umi = UserMenuinfo.fetch();
            umi.setMenuId(mi.getId());
            umi.setMenuCode(mi.getMenuCode());
            umi.setUserId(ConstDefine.T_USER_SUPERADMIN_ID);
            umi.setUserCode(ConstDefine.T_USER_SUPERADMIN_CODE);
            list.add(umi);
        }
    }
    else{
        conditions.add(USER_ID, code);
        list = UserMenuinfo.fetch().search(con, conditions);
    }
    return list;
}

//----add by Sindy end----//

//----add by wing start----//
public static boolean IsExistBySubMenus(ObjectList userMenuinfoList,int menuCode) throws Exception
{
    boolean menuExist = false;
    if(userMenuinfoList != null) {
        for(int i=0; i<userMenuinfoList.size();i++){
            UserMenuinfo userMenuinfo = (UserMenuinfo)userMenuinfoList.get(i);
            if (userMenuinfo.getMenuCode() == menuCode) return true;
        }
    }
    return menuExist;
}

public static boolean IsExistHeadMenuBySubMenus(DBConnection con,ObjectList userMenuinfoList,int headHenuCode) throws Exception
{
    boolean menuExist = false;
    if(userMenuinfoList != null) {
        for(int i=0; i<userMenuinfoList.size();i++){
            UserMenuinfo userMenuinfo = (UserMenuinfo)userMenuinfoList.get(i);
            Conditions cs = new Conditions();
            cs.add(MenuInfo.MENU_CODE,userMenuinfo.getMenuCode());
            MenuInfo menuinfo = MenuInfo.fetch(con,cs);
            if (menuinfo != null)
            {
                if (menuinfo.getParentCode() == headHenuCode) 
                {
                    return true;
                }
            }
       }
    }
    return menuExist;
}

public void deleteByUserId(DBConnection con,String userId) throws Exception
{
    Conditions conditions = new Conditions();

    conditions.add(USER_ID,userId);
    
    delete(con,TABLE_NAME,conditions);
}
//----add by wing end----//

}

